package com.weather.web.business;

import com.weather.business.domain.WeatherData;
import com.weather.business.service.IWeatherDataService;
import com.weather.common.annotation.Log;
import com.weather.common.core.controller.BaseController;
import com.weather.common.core.domain.AjaxResult;
import com.weather.common.core.page.TableDataInfo;
import com.weather.common.enums.BusinessType;
import com.weather.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 城市天气Controller
 *
 * @author ruoyi
 * @date 2024-03-15
 */
@RestController
@RequestMapping("/business/weather")
public class WeatherDataController extends BaseController
{
    @Autowired
    private IWeatherDataService weatherDataService;

    /**
     * 查询城市天气列表
     */
//    @PreAuthorize("@ss.hasPermi('business:weather:list')")
    @GetMapping("/list")
    public TableDataInfo list(WeatherData weatherData)
    {
        startPage();
        List<WeatherData> list = weatherDataService.selectWeatherDataList(weatherData);
        return getDataTable(list);
    }

    /**
     * 查询今日城市天气列表
     */
//    @PreAuthorize("@ss.hasPermi('business:weather:list')")
    @GetMapping("/all")
    public List<WeatherData> all(WeatherData weatherData)
    {
        List<WeatherData> list = weatherDataService.selectWeatherDataAllList(weatherData);
        return list;
    }

    /**
     * 导出城市天气列表
     */
    @PreAuthorize("@ss.hasPermi('business:weather:export')")
    @Log(title = "城市天气", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WeatherData weatherData)
    {
        List<WeatherData> list = weatherDataService.selectWeatherDataList(weatherData);
        ExcelUtil<WeatherData> util = new ExcelUtil<WeatherData>(WeatherData.class);
        util.exportExcel(response, list, "城市天气数据");
    }

    /**
     * 获取城市天气详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:weather:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(weatherDataService.selectWeatherDataById(id));
    }

    /**
     * 新增城市天气
     */
    @PreAuthorize("@ss.hasPermi('business:weather:add')")
    @Log(title = "城市天气", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WeatherData weatherData)
    {
        return toAjax(weatherDataService.insertWeatherData(weatherData));
    }

    /**
     * 修改城市天气
     */
    @PreAuthorize("@ss.hasPermi('business:weather:edit')")
    @Log(title = "城市天气", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WeatherData weatherData)
    {
        return toAjax(weatherDataService.updateWeatherData(weatherData));
    }

    /**
     * 删除城市天气
     */
    @PreAuthorize("@ss.hasPermi('business:weather:remove')")
    @Log(title = "城市天气", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(weatherDataService.deleteWeatherDataByIds(ids));
    }
}
